using System;

namespace IPD_GeneralLib
{
	/// <summary>
	/// 
	/// </summary>
	
public partial class IPDGeneral
 {
 	bool bLogcreate = true ; // Create or Append to debuglog file
    bool bcontactsByFirstName_Sorted ; // To detect first name / last name in contact DB
    bool bcontactsfield32_2ndTime;
    bool bEOF_Reached;
    
	static string sLogfile_locate;
	internal static int iInterfaceLanguage ;
	internal static int[] iContactsPicture_Imagetype;
	internal const int CIpdImageType_Jpeg  = 1 ;
	internal const int CIpdImageType_Gif = 2 ;
	internal const int CIpdImageType_Unknown = -1 ;
	internal static string sHelpImportCsv = "";

    private const int CMAX_DB_IN_IPD = 512;
    
	internal const int CMAXROW_VIRTUALARRAY = 1000 ;
	
	internal const int CIPDERROR_NOERROR = 0 ;
	internal const int CIPDERROR_DatabaseUnknown  = -4 ;
	internal const int CIPDERROR_FileCreateError = -5 ;
	internal const int CIPDERROR_FileWriteError  = -6 ;
	internal const int CIPDERROR_IpdNotFound = -7 ;
	internal const int CIPDERROR_TooManyRows_InDb = -8 ;
	internal const int CIPDERROR_FileNotFound = -9 ;
	internal const int CIPDERROR_NotAnIpd = -10 ;
	internal const int CIPDERROR_UnexpectedIpdEof = -11 ;
	internal const int CIPDERROR_TooManyLines_InFile = -12 ;
	internal const int CIPDERROR_TooManyNotEnoughRows = -14 ;
	internal const int CIPDERROR_FileError  = -15 ;

// Arrays content of known DataBases in this version
    public static string[,] VirtualArray_Memos          ;
	public static string[,] VirtualArray_Phone_Call_Log ;
	public static string[,] VirtualArray_Tasks          ;
	public static string[,] VirtualArray_SMS            ;
	public static string[,] VirtualArray_Calendar       ;
	public static string[,] VirtualArray_Contacts       ;
	//public static string[,] VirtualArray_Messages       ;

// ID of known DB
internal struct dbabsoluteid {
           internal int  absolute_idMemos ;
           internal int  absolute_idPhone_Call_Log ;
           internal int  absolute_idTasks ;
           internal int  absolute_idSMS ;
           internal int  absolute_idCalendar ;
           internal int  absolute_idContacts ;
           //internal int  absolute_idMessages ;
       }
internal static dbabsoluteid DBAbsoluteIdentifier = new dbabsoluteid() ;

// Various object for file management
internal static System.IO.BinaryReader Input_IPD_File_binReader ; // IPD file open
internal static System.IO.FileInfo     Input_IPD_File_f ;
internal static System.IO.FileStream   Input_IPD_File_fs ; // used only for position in file when reading

internal static System.IO.StreamWriter sw100 ; // Dump csv, vcard, vcal files

internal static System.IO.BinaryWriter wb101 ; // Dump binary buffer (debug purpose)
internal static System.IO.BinaryWriter wb103 ; // Other Dump binary buffer (debug purpose)

internal static System.IO.BinaryWriter Output_IPD_File_binWriter ; // Ipd creation

	 

// variables references SMS
internal static int SMS_ColDateSent;
internal static int SMS_ColDateReceived;
internal static int SMS_ColStatus;
internal static int SMS_ColFolder;
internal static int SMS_ColPhone;
internal static int SMS_ColMsg;
// Column names for display or csv creation purpose. WARNING names order is VERY important
internal static string [] sSms_Col_Names = new string[] {"Date_Sent", "Date_Received", "Status", "Folder", "Phone", "Message"} ;
// To create an SMS IPD file
internal static int[] iSMS_fieldresolved;
// message text in SMS could be 7bits or unicode (UCS-2)
internal bool bSMS_messisUCS2;


// variables references MEMOS
internal static int MEMOS_ColSubject ;
internal static int MEMOS_ColNotes ;
// Column names for display or csv creation purpose. WARNING names order is VERY important
internal static string [] sMemo_Col_Names = {"Subject", "Notes"} ;

// variables references TASKS
internal static int TASKS_ColName;
internal static int TASKS_ColNotes;
internal static int TASKS_ColDate;
internal static int TASKS_ColRecurrence_Type;
internal static int TASKS_ColEvery;
internal static int TASKS_ColReminder;
internal static int TASKS_ColEnd;
// Column names for display or csv creation purpose
// WARNING names order is VERY important
internal static string [] sTask_Col_Names = {"Name", "Notes", "Date", "Recurrence_Type", "Every", "Reminder", "End"} ;

// variables references PHONE CALL LOG
internal static int PHONECALLLOG_ColNumber;
internal static int PHONECALLLOG_ColName;
internal static int PHONECALLLOG_ColDate;
internal static int PHONECALLLOG_ColStatus;
internal static int PHONECALLLOG_ColDuration;
// Column names for display or csv creation purpose
// WARNING names order is VERY important
internal static string [] sPhoneCallLog_Col_Names = {"Number", "Name", "Date", "Status", "Duration"} ;

// variables references CALENDAR (DATEBOOK)
internal static int CALENDAR_ColSubject;
internal static int CALENDAR_ColNotes;
internal static int CALENDAR_ColDateStart;
internal static int CALENDAR_ColDateEnd;
internal static int CALENDAR_ColRecurrence_Type;
internal static int CALENDAR_ColRecurrence_Start;
internal static int CALENDAR_ColRecurrence_End;
internal static int CALENDAR_ColEvery;
internal static int CALENDAR_ColDateAlarm;
internal static int CALENDAR_ColLocation;
// Column names for display or csv creation purpose
// WARNING names order is VERY important
internal static string [] sCalendar_Col_Names = {"Subject", "Notes", "DateStart", "DateEnd", "Recurrence_Typ", 
                                                 "Recurrence_Start", "Recurrence_End", "Every;", "DateAlarm", "Location"} ;

// variables references pour Adress Book
internal static int CONTACT_ColFirstName ;
internal static int CONTACT_ColLastName ;
internal static int CONTACT_ColHomeAddress1 ;
internal static int CONTACT_ColHomeAddress2 ;
internal static int CONTACT_ColHomeCity ;
internal static int CONTACT_ColHomeState ;
internal static int CONTACT_ColHomeZIP ;
internal static int CONTACT_ColHomeCountry ;
internal static int CONTACT_ColWorkAddress1 ;
internal static int CONTACT_ColWorkAddress2 ;
internal static int CONTACT_ColWorkCity ;
internal static int CONTACT_ColWorkState ;
internal static int CONTACT_ColWorkZIP ;
internal static int CONTACT_ColWorkCountry ;
internal static int CONTACT_ColEmail ;
internal static int CONTACT_ColCompany ;
internal static int CONTACT_ColJob ;
internal static int CONTACT_ColWebPage ;
internal static int CONTACT_ColTitle ;
internal static int CONTACT_ColCategories ;
internal static int CONTACT_ColPhoneWork ;
internal static int CONTACT_ColPhoneWork2 ;
internal static int CONTACT_ColPhoneHome ;
internal static int CONTACT_ColPhoneHome2 ;
internal static int CONTACT_ColPhoneMobile ;
internal static int CONTACT_ColPhoneMobile2 ;
internal static int CONTACT_ColPager ;
internal static int CONTACT_ColPIN ;
internal static int CONTACT_ColPhoneOther ;
internal static int CONTACT_ColHomeFax ;
internal static int CONTACT_ColWorkFax ;
internal static int CONTACT_ColUser1 ;
internal static int CONTACT_ColUser2 ;
internal static int CONTACT_ColUser3 ;
internal static int CONTACT_ColUser4 ;
internal static int CONTACT_ColBirthday ;
internal static int CONTACT_ColAnniversary ;
internal static int CONTACT_ColNotes ;
internal static int CONTACT_ColPicture ;
// Column names for display or csv creation purpose
// WARNING names order is VERY important
internal static string [] sContact_Col_Names = 
   {"First Name", "Last Name", "PhoneMobile", "Home Address1", "Home City", "Home State", "Home ZIP", 
    "Home Country", "Work Address1", "Work Address2", "Work City", "Work State", "Work ZIP", "Work Country", 
    "Email", "Company", "Job", "WebPage", "Title", "Categories", "PhoneWork", "PhoneWork2", "PhoneHome", 
    "PhoneHome2", "Home Address2", "PhoneMobile2", "Pager", "PIN", "PhoneOther", "HomeFax", "WorkFax", 
    "User1", "User2", "User3", "User4", "Birthday", "Anniversary", "Notes", "Picture"} ;

//**************************************************
internal static int iNumber_of_DBs;
internal static int iCalendar_Row;
internal static int iContacts_Row;
internal static int iMemos_Row;
internal static int iPhoneCallLogs_Row;
internal static int iSMS_Row;
internal static int iTasks_Row;

internal static long lSizeOfInputFile;

internal static string sIpd_Last_ModifiedDate;
internal static string sdelimitercsv;

//===========================
int iAddress_All_DBid;
int iCalendar_1stDay_OfWeek;
int iLatest_DBid;
int iPrevious_Latest_DBid;
int iRecurrence_bitvalue;
int iRecurrence_ctr;
int iRecurrence_dow;
int iWhich_Address_DB;
int iCalendar_ConvergeType;
int iIPD_Header_Size;

byte yField_Type;
byte[] yTbl; // Init fait apres connaissance de la taille de l'Ipd dans Start_IPD_Parse()
int iField_inData_Ptr;
int Calendar_Type_10_Active;

string sField_Data;
string sInputIPD_FileNamePath;
string sOutputFile_DirectoryName;
string sRec_data;
string sRecurrence_DaysOfWeek;
string sDateTime;

byte [] yIPD_Header;
string[] sCalendar_dayNames_sorted ;

double dDB_DataBlock_Count;
double dDB_DataBlock_RecLen;

long lAddress_All_RecLen;
long lCalendar_All_RecLen;
long lField_Len;
long lPrev_Field_Len;

internal static int iNb_DB_Managed;

internal struct dbinfo {
        internal string    sinput_ipdfilename;  // file name of Ipd analyzed
        internal int []    db_id ;              // DB ID in IPD file
        internal int []    nb_datablock_indb ;  // Nb datablock for each db in ipd. At this moment only for debug purpose
        internal string [] db_names ;           // DB name
        internal int []    idb_names_len ;
        internal bool   [] db_Dbexists_inipd ; // Data Base exists in IPD file
        internal bool   [] db_Ok_toprocess ;   // si "True" on traite cette DB, sinon on ne traite pas.
        
        internal string [] dbmanaged_names ;           // Only managed here, DB names
        internal int []    dbmanaged_id ;              // Only managed here, DB ID
        internal int       ismaller_dbmanaged_id ;
        internal int       ibigger_dbmanaged_id ;
        
    }
     internal static dbinfo DB_Info = new dbinfo() ;
}
}
